package com.bw.mvvm_common.bind;

import androidx.databinding.BindingAdapter;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.chad.library.adapter.base.BaseQuickAdapter;

/**
 * @author KK
 * @description:
 * @date :2021/10/14 17:56
 * Recyclerview 自定义公共属性
 */
public class BasicRvBind {

    @BindingAdapter(value = "adapter")
    public static  void bindAdapter(RecyclerView recyclerView, BaseQuickAdapter adapter){
        recyclerView.setAdapter(adapter);
    }

    @BindingAdapter(value = "orientation")
    public static void bindLinnerManager(RecyclerView recyclerView,int orientation){
        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(recyclerView.getContext());
        linearLayoutManager.setOrientation(orientation);
        recyclerView.setLayoutManager(linearLayoutManager);
    }

    @BindingAdapter(value = {"orientation","rvnum"})
    public static void bindGridManager(RecyclerView recyclerView,int orientation,int rvnum){
        GridLayoutManager gridLayoutManager = new GridLayoutManager(recyclerView.getContext(), rvnum);
        gridLayoutManager.setOrientation(orientation);
        recyclerView.setLayoutManager(gridLayoutManager);
    }


}
